<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .outer {
            display: flex;
            align-items: center;
            justify-content: space-evenly;
            width: 800px;
            height: 200px;
            margin: 20px auto;
            border: 1px solid #bb0bbe;
        }

        .inner {
            position: relative;
            width: 600px;
            height: 8px;
            background-color: #E4E7ED;
            border-radius: 4px;
        }

        .blue {
            position: absolute;
            top: 0;
            left: 0;
            height: 8px;
            width: 0;
            background-color: #0e4dca;
            border-radius: 4px;
        }

        .circle {
            position: absolute;
            top: -5px;
            /* right: 0; */
            left: -9px;
            width: 16px;
            height: 16px;
            background-color: #fff;
            border: 2px solid #0e4dca;
            border-radius: 50%;
        }

        .black {
            display: none;
            position: absolute;
            top: -55px;
            left: -15px;
            width: 30px;
            height: 40px;
            line-height: 40px;
            background-color: #000;
            border-radius: 4px;
            color: #fff;
            text-align: center;
        }

        .black::after {
            position: absolute;
            left: 10px;
            bottom: -11px;
            display: block;
            content: '';
            width: 0;
            height: 0;
            border: 6px solid transparent;
            border-top-color: #000;

        }
    </style>
</head>

<body>
    <div class="outer">
        <span>滑动条</span>
        <div class="inner">
            <div class="blue">
                <div class="circle"></div>
            </div>
            <div class="black">0</div>
        </div>
    </div>
    <script>
        var circle = document.querySelector('.circle');
        var blue = document.querySelector('.blue');
        var black = document.querySelector('.black');

        circle.onmouseenter = function () {
            black.style.display = 'block';
        }
        circle.onmouseleave = function () {
            black.style.display = '';
        }

        var inner = document.querySelector('.inner');
        var clickLeft = 0;
        inner.onclick = function (ev) {
            var left = ev.pageX - this.offsetLeft;
            left = left < 0 ? 0 : left;
            left = left > this.offsetWidth ? this.offsetWidth : left;

            blue.style.width = left + 'px';
            circle.style.left = left - 9 + 'px';
            black.style.left = left - 15 + 'px';
            black.innerHTML = Math.round(left / this.offsetWidth * 100);

            clickLeft = left;


        }



        circle.onmousedown = function (ev) {
            document.onmousemove = function (ev) {
                var left = ev.pageX - inner.offsetLeft;
                left = left < 0 ? 0 : left;
                left = left > inner.offsetWidth ? inner.offsetWidth : left;

                blue.style.width = left + 'px';
                circle.style.left = left - 9 + 'px';
                black.style.left = left - 15 + 'px';
                black.innerHTML = Math.round(left / inner.offsetWidth * 100);
            }
        }
        document.onmouseup = function () {
            document.onmousemove = null;
        }
    </script>
</body>

</html>